#!/usr/bin/env node

import { CLI } from './cli';
import { logger } from './utils/logger';

async function main() {
  try {
    const cli = new CLI();

    process.on('SIGINT', async () => {
      logger.info('收到中断信号，正在清理资源...');
      process.exit(0);
    });

    process.on('SIGTERM', async () => {
      logger.info('收到终止信号，正在清理资源...');
      process.exit(0);
    });

    process.on('uncaughtException', (error) => {
      logger.error('未捕获的异常:', error);
      process.exit(1);
    });

    process.on('unhandledRejection', (reason) => {
      logger.error('未处理的Promise拒绝:', reason);
      process.exit(1);
    });

    await cli.run();
  } catch (error) {
    logger.error('程序启动失败:', error);
    process.exit(1);
  }
}

main();